package com.jl.card.filesystem;

import java.util.HashMap;

import com.jl.util.HexUtil;

public final class CardFileNameDescription {

	public static String getFileNameByID(short topDF, short id) {
		int nTopDF = topDF & 0xFFFF;
		int nid = id & 0xFFFF;
		if (FILE_NAME_MAP.containsKey(nTopDF)) {
			HashMap<Integer, String> m = FILE_NAME_MAP.get(nTopDF);
			if (m.containsKey(nid)) {
				return m.get(nid);
			}
		}
		if(id == 0x3f00){
			return "MF";
		}
		return "UNKNOWN";
	}

	public static String getFileNameByID(String topDF, String id) {
		byte[] b = HexUtil.parseHexToByteArray(id);
		byte[] b2 = HexUtil.parseHexToByteArray(topDF);
		return getFileNameByID(HexUtil.makeShort(b2, 0),
				HexUtil.makeShort(b, 0));
	}

	private final static HashMap<Integer, HashMap<Integer, String>> FILE_NAME_MAP = new HashMap<Integer, HashMap<Integer, String>>();

	private final static HashMap<Integer, String> topDF_3F00 = new HashMap<Integer, String>();
	private final static HashMap<Integer, String> topDF_7f10 = new HashMap<Integer, String>();
	private final static HashMap<Integer, String> topDF_7f20 = new HashMap<Integer, String>();
	private final static HashMap<Integer, String> topDF_7f22 = new HashMap<Integer, String>();
	private final static HashMap<Integer, String> topDF_7f23 = new HashMap<Integer, String>();
	private final static HashMap<Integer, String> topDF_7f4a = new HashMap<Integer, String>();

	static {
		// top DF
		FILE_NAME_MAP.put(0x3f00, topDF_3F00);
		FILE_NAME_MAP.put(0x7f10, topDF_7f10);
		FILE_NAME_MAP.put(0x7f20, topDF_7f20);
		FILE_NAME_MAP.put(0x7f22, topDF_7f22);
		FILE_NAME_MAP.put(0x7f23, topDF_7f23);
		FILE_NAME_MAP.put(0x7f4a, topDF_7f4a);

		topDF_3F00.put(0x7f10, "TELECOM");
		topDF_3F00.put(0x7f20, "GSM");
		topDF_3F00.put(0x7f22, "IS-41");
		topDF_3F00.put(0x7f23, "FP-CTS");
		topDF_3F00.put(0x7f4a, "TEST");

		topDF_3F00.put(0x2f00, "DIR");
		topDF_3F00.put(0x2f05, "ELP/PL");
		topDF_3F00.put(0x2f06, "ARR");
		topDF_3F00.put(0x2fe2, "ICCID");
		topDF_3F00.put(0x2fe4, "UICC");

		// TELECOM 7f10
		topDF_7f10.put(0x6f3a, "ADN");
		topDF_7f10.put(0x6f3b, "FDN");
		topDF_7f10.put(0x6f3c, "SMS");
		topDF_7f10.put(0x6f3d, "CCP");
		topDF_7f10.put(0x6f40, "MSISDN");
		topDF_7f10.put(0x6f42, "SMSP");
		topDF_7f10.put(0x6f43, "SMSS");
		topDF_7f10.put(0x6f44, "LND");
		topDF_7f10.put(0x6f47, "SMSR");
		topDF_7f10.put(0x6f49, "SDN");
		topDF_7f10.put(0x6f4a, "EXT1");
		topDF_7f10.put(0x6f4b, "EXT2");
		topDF_7f10.put(0x6f4c, "EXT3");
		topDF_7f10.put(0x6f4d, "BDN");
		topDF_7f10.put(0x6f4e, "EXT4");
		topDF_7f10.put(0x5f50, "GRAPHICS");
		topDF_7f10.put(0x4f20, "IMG");
		// 7f20
		topDF_7f20.put(0x5f30, "IRIDIUM");
		topDF_7f20.put(0x5f31, "GLOBST");
		topDF_7f20.put(0x5f32, "ICO");
		topDF_7f20.put(0x5f33, "ACeS");
		topDF_7f20.put(0x5f40, "EIA/TIA-553");
		topDF_7f20.put(0x5f60, "CTS");
		topDF_7f20.put(0x5f70, "SoLSA");
		topDF_7f20.put(0x4f30, "SAI");
		topDF_7f20.put(0x4f31, "SLL");
		topDF_7f20.put(0x5f3c, "MExE");
		topDF_7f20.put(0x4f40, "MExE-ST");
		topDF_7f20.put(0x4f41, "ORPK");
		topDF_7f20.put(0x4f42, "ARPK");
		topDF_7f20.put(0x4f43, "TPRPK");
		topDF_7f20.put(0x6f05, "LP");
		topDF_7f20.put(0x6f07, "IMSI");
		topDF_7f20.put(0x6f20, "Kc");
		topDF_7f20.put(0x6f30, "PLMNsel");
		topDF_7f20.put(0x6f31, "HPLMN");
		topDF_7f20.put(0x6f37, "ACMmax");
		topDF_7f20.put(0x6f38, "SST");
		topDF_7f20.put(0x6f39, "ACM");
		topDF_7f20.put(0x6f3e, "GID1");
		topDF_7f20.put(0x6f3f, "GID2");
		topDF_7f20.put(0x6f41, "PUCT");
		topDF_7f20.put(0x6f45, "CBMI");
		topDF_7f20.put(0x6f46, "SPN");
		topDF_7f20.put(0x6f48, "CBMID");
		topDF_7f20.put(0x6f74, "BCCH");
		topDF_7f20.put(0x6f78, "ACC");
		topDF_7f20.put(0x6f7B, "FPLMN");
		topDF_7f20.put(0x6f7E, "LOCI");
		topDF_7f20.put(0x6fAD, "AD");
		topDF_7f20.put(0x6fAE, "PHASE");
		topDF_7f20.put(0x6fb1, "VGCS");
		topDF_7f20.put(0x6fb2, "VGCSS");
		topDF_7f20.put(0x6fb3, "VBS");
		topDF_7f20.put(0x6fb4, "VBSS");
		topDF_7f20.put(0x6fb5, "eMLPP");
		topDF_7f20.put(0x6fb6, "AAeM");
		topDF_7f20.put(0x6fb7, "ECC");
		topDF_7f20.put(0x6f51, "NIA");
		topDF_7f20.put(0x6f50, "CBMIR");
		topDF_7f20.put(0x6f52, "KcGPRS");
		topDF_7f20.put(0x6f53, "LOCIGPRS");
		topDF_7f20.put(0x6f54, "SUME");
		topDF_7f20.put(0x6f60, "PLMNwAcT");
		topDF_7f20.put(0x6f61, "OPLMNwAcT");
		topDF_7f20.put(0x6f62, "HPLMNAcT");
		topDF_7f20.put(0x6f63, "CPBCCH");
		topDF_7f20.put(0x6f64, "INVSCAN");
		topDF_7f20.put(0x6f65, "RPLMNAT");

	}
}
